// import Token from '../../utils/token';
// import { PASSWORDERROR, USERNOEXIST } from '../../utils/error';
const assert = require('assert');
// const macObj = require('getmac');
const BasicController = require('../BasicController.js');

module.exports = class extends BasicController {
  constructor(ctx) {
    super(ctx);
    assert(think.isFunction(this.model), 'this.model must be a function');
    this.MODEL = this.ctx.state.ApiInfo.model;
    this.params = {
      model: this.MODEL,
      data: this.post()
    };
  }
  async getpermissionAction() {
    const data = this.params.data;
    const databack = await this.model(this.MODEL).where(data).find();
    const arr = databack.permission.split(',');
    databack.permission = arr;
    this.success(databack, 'ok');
  }
};

/**
 * @api {POST} /role/role/listall /listall
 * @apiName listall
 * @apiGroup role
 * @apiParam {String} [id] 角色ID
 * @apiParam {String} [role] 角色名称
 * @apiParam {String} [memo] 角色注解
 *
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
    "data":  [
        {
            "id": "1",
            "role": "superadmin",
            "memo": "超级管理员",
            "create_time": "2018-07-04 14:50:51",
            "edit_time": null,
            "menu_id": "1;2;3;5;8"
        },
        {
            "id": "2",
            "role": "admin",
            "memo": "管理员",
            "create_time": "2018-07-04 14:51:06",
            "edit_time": null,
            "menu_id": "1;2;3;5;8"
        },
        {
            "id": "3",
            "role": "user",
            "memo": "用户",
            "create_time": "2018-07-04 14:51:20",
            "edit_time": null,
            "menu_id": "4"
        }
    ]
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *           "errno": 0,
    "errmsg": "",
    "data": {
    }
 *     }
 * @apiParamExample {post} Request-Example:
                 {
                  }
 */
/**
 * @api {POST} /role/role/getpermission /getpermission
 * @apiName getpermission
 * @apiGroup role
 * @apiParam {String} id 角色ID
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
    "data":  {
        "id": "1",
        "role": "superadmin",
        "memo": "超级管理员",
        "permission": [
            "1",
            "2",
            "3",
            "4"
        ],
        "create_time": "2018-07-04 14:50:51",
        "edit_time": "2018-08-09 16:09:12"
    }
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *           "errno": 0,
    "errmsg": "",
    "data": {
    }
 *     }
 * @apiParamExample {post} Request-Example:
                 {
                     id:1,
                  }
 */
/**
 * @api {POST} /role/role/add /add
 * @apiName add
 * @apiGroup role
 * @apiParam {String} [role] 用户名称
 * @apiParam {String} [memo] 用户注解
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
    "data":  [
        {
            "id": "1",
            "role": "superadmin",
            "memo": "超级管理员",
            "create_time": "2018-07-04 14:50:51",
            "edit_time": null
        }
    ]
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *           "errno": 0,
    "errmsg": "",
    "data": {
    }
 *     }
 * @apiParamExample {post} Request-Example:
                 {
                  }
 */
/**
 * @api {POST} /role/role/listpage /listpage
 * @apiName listpage
 * @apiGroup role
 * @apiParam {String} [page] 页数、
 * @apiParam {String} [pageSize] 每页数据条数
 * @apiParam {String} [role] 用户名称
 * @apiParam {String} [memo] 用户注解
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
    "data":  [
        "pageSize": 20,
        "current": 1,
        "pages": 1,
        "total": 3,
        dataL:[
        {
            "id": "1",
            "role": "superadmin",
            "memo": "超级管理员",
            "create_time": "2018-07-04 14:50:51",
            "edit_time": null
        }
        ]
    ]
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *           "errno": 0,
    "errmsg": "",
    "data": {
    }
 *     }
 * @apiParamExample {post} Request-Example:
                 {
                  }
 */
/**
 * @api {POST} /role/role/edit /edit
 * @apiName edit
 * @apiGroup role
 * @apiParam {String} [permission] 菜单ID集
 * @apiParam {String} [role] 用户名称
 * @apiParam {String} [memo] 用户注解
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
     dataL:[
        {
            "id": "1",
            "role": "superadmin",
            "memo": "超级管理员",
            "permission": "1,2,3,4",
            "create_time": "2018-07-04 14:50:51",
            "edit_time": null
        }
        ]
    ]
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *           "errno": 0,
    "errmsg": "",
    "data": {
    }
 *     }
 * @apiParamExample {post} Request-Example:
                 {
                    id:'1',
                    permission:'1,2,3,4,5'
                  }
 */
/**
 * @api {DELETE} /role/role/del /del
 * @apiName del
 * @apiGroup role
 * @apiParam {String} id 组别ID
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
     data:[
        ]
    ]
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *           "errno": 0,
    "errmsg": "",
    "data": {
    }
 *     }
 * @apiParamExample {delete} Request-Example:
                 {
                    id:'1',
                  }
 */
/**
 * @api {GET} /role/role/get /get
 * @apiName get
 * @apiGroup role
 * @apiParam {String} id 组别ID
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
     data:{
                     "id": "1",
            "role": "superadmin",
            "memo": "超级管理员",
            "permission": "1,2,3,4",
            "create_time": "2018-07-04 14:50:51",
            "edit_time": null
     }
    ]
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *           "errno": 0,
    "errmsg": "",
    "data": {
    }
 *     }
 * @apiParamExample {get} Request-Example:
                 {
                    id:'1',
                  }
 */
